﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.Configuration;
using System.Globalization;


namespace NormReferenceWindowsService
{
    public partial class WindowsService : ServiceBase
    {
        private Timer timer;

        public WindowsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            InitializeTimer();
        }

        protected override void OnStop()
        {
        }

        protected void RunJob()
        {
            NormReferenceServiceClient client = new NormReferenceServiceClient();
            client.NormReference();
        }

        private void InitializeTimer()
        {
            if (timer == null)
            {
                timer = new Timer();
                timer.AutoReset = true;
                timer.Interval = 6000 * Convert.ToDouble(ConfigurationSettings.AppSettings["IntervalMinurates"]);
                timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            }
        }

        private void timer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
        {
            RunJob();
        }
    }
}
